package com.yztc.ui.shopping;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;

import com.yztc.chunboapp.MainActivity;
import com.yztc.chunboapp.R;
import com.yztc.ui.LoginActivity;

/**
 * Created by My on 2016/10/6.
 */
public class ShoppingFragment extends Fragment {
    //登录按钮,点击去逛逛按钮,跳转到首页
    private Button mBtnLogin,mBtnGuangGuang;
    //进入评论页面
    private ImageButton mIBtnEnter;
    //登录前后两个界面布局
    private LinearLayout mLineBefore,mLineAfter;
    //登录后的 逛逛按钮
    private Button mBtnGuangGuang1;
    private View view;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_shopping,null);
        initView();
        //设置监听
        setOnClickListener();
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        //判断用户登录状态
        if (MainActivity.tag == true){
            //假如用户已经登录，则隐藏注册、登录按钮布局
            mLineBefore.setVisibility(View.GONE);
            //用户信息布局回复可见
            mLineAfter.setVisibility(View.VISIBLE);
        }else {
            //假如用户未登录，则隐藏用户信息布局
            mLineAfter.setVisibility(View.GONE);
            //注册、登录按钮布局回复可见
            mLineBefore.setVisibility(View.VISIBLE);
        }

    }

    private void setOnClickListener() {
        //点击登录按钮，跳转到登录页面
        mBtnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), LoginActivity.class);
                startActivity(intent);
            }
        });
        //点击enter ImageButton ,跳转到评论页面
        mIBtnEnter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        //点击去逛逛按钮,跳转到首页【登录前显示的按钮】
        mBtnGuangGuang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               if (MainActivity.mHomeFragment != null){
                   Intent intent = new Intent(getActivity(),MainActivity.class);
                   startActivity(intent);
               }

            }
        });
        //点击去逛逛按钮01,跳转到首页【登录后显示的按钮】
        mBtnGuangGuang1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(),MainActivity.class);
                startActivity(intent);
            }
        });
    }

    private void initView() {
        mBtnLogin = (Button) view.findViewById(R.id.btn_shopping_login);
        mIBtnEnter = (ImageButton) view.findViewById(R.id.ibtn_shopping_enter);
        mBtnGuangGuang = (Button) view.findViewById(R.id.btn_shopping_guanguang);
        mLineBefore = (LinearLayout) view.findViewById(R.id.line_shopping_before);
        mLineAfter = (LinearLayout) view.findViewById(R.id.line_shopping_after);
        mBtnGuangGuang1 = (Button) view.findViewById(R.id.btn_shopping_guanguang01);
    }
}
